﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading;
using UDS.Components;

namespace UDS.Entity
{
    public class CatalogInfo
    {
        #region properties
        public int CatalogID
        {
            get;
            set;
        }

        public string Catalog
        {
            get;
            set;
        }

        /// <summary>
        /// The username of the creator.
        /// </summary>
        public string Creator
        {
            get;
            set;
        }

        private string creatorRealName;

        /// <summary>
        /// Get the real name of the creator.
        /// </summary>
        public string CreatorRealName
        {
            get
            {
                if (creatorRealName == null)
                {
                    Interlocked.CompareExchange(ref creatorRealName, Staff.GetRealNameByUsername(Creator), null);
                }
                return creatorRealName;
            }
        }

        public DateTime TimeCreated
        {
            get;
            set;
        }
        #endregion

        internal static CatalogInfo ReadCatalogInfo(IDataReader dr)
        {
            CatalogInfo g = new CatalogInfo();
            g.CatalogID = (int)dr["CatalogID"];
            g.Catalog = Convert.ToString(dr["Catalog"]);
            g.Creator = Convert.ToString(dr["Creator"]);
            g.TimeCreated = Convert.ToDateTime(dr["TimeCreated"]);
            return g;
        }
    }
}
